<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ leftCount }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: this.type === 'all' }"
          @click="$emit('typeTodo', 'all')"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: this.type === 'no' }"
          @click="$emit('typeTodo', 'no')"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: this.type === 'yes' }"
          @click="$emit('typeTodo', 'yes')"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clear" v-show="clearAll">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array, // 数组类型
      required: true, // 必传参
    },
    type: {
      type: String, // 字符串类型
      required: true, // 必传参
    },
  },
  computed: {
    leftCount() {
      // 剩余未完成的数量
      return this.list.filter((item) => !item.isDone).length
    },
    clearAll() {
      // 检测是否有已完成的数据
      return this.list.some((item) => item.isDone)
    },
  },
  methods: {
    clear() {
      this.$emit('clearNo')
    },
  },
}
</script>
